let app = getApp();
Page({
  data: {
    infor: [],
    firstRow:0,
    is_show_time: 1,
    userName:'',
    k: wx.getStorageSync('key'),
    u: wx.getStorageSync('u'),
    search_show: false,
    is_show: 0,
    
  },
  onLoad: function () {
    var that = this
   
    if (that.data.u){
      wx.request({
        url: app.configData.shop.api_url + '/index.php?ctl=Distribution_Buyer_Directseller&met=directsellerList&typ=json',
        data: { k: that.data.k, u: that.data.u },
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: function (res) {

          if (res.data.status == 200) {
            that.setData({
              infor: res.data.data.items,
              is_show_time: 0,
              is_show: 0,
            })

          }
        }
      })
    }
    
  },
 
  // 搜索
  contentInput: function (re) {
     console.log(re)
    var that = this
    if (re.detail.value) {
      that.setData({
        userName: re.detail.value,
        search_show: true
      })
    } else {
      that.setData({
        search_show: false
      })
    }

  },
  search_clear: function () {
    this.setData({
      userName: '',
      search_show: false

    })
  },
  //搜索
  bindViewTap: function (e) {
    var that = this
    var userName =that.data.userName
    
      wx.request({
        url: app.configData.shop.api_url + '/index.php?ctl=Distribution_Buyer_Directseller&met=directsellerList&typ=json',
        data: { k: that.data.k, u: that.data.u, userName: userName },
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: function (res) {

          if (res.data.status == 200) {
            that.setData({
              infor: res.data.data.items,
              is_show: 0,
            })

          }
        }
      })
    

  },
  //页面上拉触底事件的处理函数
  onReachBottom: function () {
    var that = this
    if (that.data.is_show == 1) {
      return false
    }
    that.setData({
      firstRow: that.data.firstRow + 10
    })

    wx.request({
      url: app.configData.shop.api_url + '/index.php?ctl=Distribution_Buyer_Directseller&met=directsellerList&typ=json',
      header: {
        'content-type': 'application/json'
      },
      data: { k: that.data.k, u: that.data.u, firstRow: that.data.firstRow},
      method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        
        var infor = that.data.infor
        if (res.data.data.items.length > 0) {

          for (var z in res.data.data.items) {
            infor.push(res.data.data.items[z])
          }
          that.setData({
            infor: infor,
            is_show_time: 0,
            is_show: 0

          })
        } else {
          that.setData({
            is_show: 1,
            is_show_time: 0

          })
        }

      }
    })
  },
  bindhref: function () {
    app.goTop()
    this.setData({
      show: 0
    })
  },
  //一键到顶
  onPageScroll: function (e) {
    // 获取滚动条当前位置
    var that = this
    wx.getSystemInfo({
      success: function (res) {

        if (e.scrollTop + res.windowHeight > res.windowHeight) {
          
          that.setData({
            show: 1
          })
        } else {
          
          that.setData({

            show: 0
          })
        }
      },
    })
  },
})